﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.12
import QtMultimedia 5.14
import QtGraphicalEffects 1.0
import "./components/"
import "./exportReport"
import "./animation"
import "./licenseManager/"
Item {
    id: root
    height: 41*dp  // 标题栏高度，可以根据实际需求调整
    z:1;
    width: parent.width
    Rectangle{          // 拼起来的背景
        radius: mainwindow_rect.radius
        color: "#F0F0FF"
        width: mainwindow_rect.width-2; height: 20*dp
        x: 1; y: 1
        Rectangle {
            width: mainwindow_rect.width-2
            y: 10*dp; height: 30*dp
            color: "#F0F0FF"
        }
    }
    // 这里放置你的图标和文字等，比如一个简单的应用图标和标题文字
    Row {
        anchors.verticalCenter: parent.verticalCenter
        spacing: 5*dp
        x:10*dp; y: 1*dp
        Image {
            source: "qrc:/picture/tb.png"  // 替换为你的应用图标路径
            x:5*dp
            width: 20*dp
            height: 20*dp
            anchors.verticalCenter: parent.verticalCenter
        }
        Text {
            text: "靶材核素分离软件"
            font.pixelSize: config.fontsize
            anchors.verticalCenter: parent.verticalCenter
        }
    }
    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton
        property bool isDoubleClicked: false
        property point clickPos: "0,0"

        onPressed: {
            isDoubleClicked = false
            clickPos = Qt.point(mouse.x, mouse.y)
        }

        onPositionChanged: {
            if (!isDoubleClicked && pressed && mainwindow.visibility !== Window.Maximized && mainwindow.visibility !== Window.FullScreen) {
                var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
                mainwindow.x += delta.x
                mainwindow.y += delta.y
            }
            if (mainwindow.visibility === Window.Maximized && pressed && !isDoubleClicked) {
                mainwindow.showNormal()
            }
        }

        onDoubleClicked: {
            isDoubleClicked = true
            if (isWindowMaximized) {
                mainwindow.showNormal()
            } else {
                mainwindow.showMaximized()
            }
        }
    }

    // 右侧的按钮区域
    Row {
        y: 1*dp
        anchors.verticalCenter: parent.verticalCenter
        x: parent.width - implicitWidth - 1*dp
        CustomButton {      // 切换
            height: 40*dp; width: 50*dp
            button_icon: flagtab!==0 ? "qrc:/picture/j_qhxxb.png" : "qrc:/picture/x_qhjhb.png"
            icon_size: 25*dp
            button_color_hover: Qt.rgba(0, 0, 0, 0.1)
            onClicked: {
                flagtab = 1-flagtab
            }
            CustomTooltip{
                visible: parent.isHovered
                text: flagtab===0?"切换简化版":"切换详细版"
            }
        }CustomButton {     // 帮助
            height: 40*dp; width: 50*dp
            button_icon: "qrc:/picture/t_bz.png"
            icon_size: 27*dp
            button_color_hover: Qt.rgba(0, 0, 0, 0.1)
            CustomTooltip{
                visible: parent.isHovered
                text: "帮助"
            }
            onClicked: {
            }
        }CustomButton {     // 最小化
            height: 40*dp; width: 50*dp
            button_icon: "qrc:/picture/ty_zxh.png"
            icon_size: 30*dp
            button_color_hover: Qt.rgba(0, 0, 0, 0.1)
            onClicked: {
                mainwindow.showMinimized()  // 调用窗口的最小化方法
            }
            CustomTooltip{
                visible: parent.isHovered
                text: "最小化"
            }
        }CustomButton {     // 最大化
            height: 40*dp; width: 50*dp
            button_color_hover: Qt.rgba(0, 0, 0, 0.1)
            button_icon: isWindowMaximized ?  "qrc:/picture/ty_zdh2.png" : "qrc:/picture/ty_zdh.png"
            icon_size: 27*dp
            onClicked: {
                if (isWindowMaximized) {
                    mainwindow.showNormal()
                } else {
                    mainwindow.showMaximized()
                }
            }
            CustomTooltip{
                visible: parent.isHovered
                text: isWindowMaximized?"还原":"最大化"
            }
        }CustomButton {     // 关闭
            height: 40*dp; width: 50*dp
            button_icon: "qrc:/picture/ty_gb.png"
            button_icon_hover: "qrc:/picture/ty_gb2.png"
            icon_size: 30*dp
            button_color_hover: Qt.rgba(1, 0, 0, 0.5)
            icon_color_hover: white
            onClicked: {
                Qt.quit()  // 关闭整个应用
            }
            CustomTooltip{
                visible: parent.isHovered
                text: "关闭"
            }
        }
    }
}


